import sys
import pygame
from drop import Drop
import random

def cheeck_events(bucket):
    # 监视键盘和鼠标事件
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            check_keydown_events(event,bucket)
        elif event.type == pygame.KEYUP:
            check_keyup_events(event,bucket)

def check_keydown_events(event, bucket):
    if event.key == pygame.K_RIGHT:
        bucket.moving_right = True
    elif event.key == pygame.K_LEFT:
        bucket.moving_left = True
def check_keyup_events(event, bucket):
    if event.key == pygame.K_RIGHT:
        bucket.moving_right = False
    elif event.key == pygame.K_LEFT:
        bucket.moving_left = False




def update_screen(dg_settings,screen,bucket,drops):
    # 每次循环时重绘屏幕
    screen.fill(dg_settings.bg_color)
    bucket.blitme()
    for drop in drops:
        drop.blitme()
    # 让最近绘制的屏幕可见
    pygame.display.flip()


def check_beat(bucket,drops):
    for drop in drops:
        if pygame.sprite.collide_rect(bucket,drop):
            drops.remove(drop)
            drop_sound = pygame.mixer.Sound('audio/drop.wav')
            drop_sound.play()
            break

def check_bottom_drops(screen,drops):
    for drop in drops:
        if drop.rect.bottom>screen.get_rect().bottom:
            drops.remove(drop)
            break